package com.yuelife.until;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author by Rxzeg
 * @date 2020-06-18 17:27
 * @describe
 */
public class TimeHelper {

    public String getTime(int num){
        String time=null;
        Date date=new Date(new Date().getTime()+num);
        int hour1=date.getHours();
        int minute1=date.getMinutes();
        int second=date.getSeconds();
        int c_time=hour1*60*60*1000+minute1*60*1000+second*1000;
        String hour=date.getHours() < 10 ? "0" + date.getHours() : date.getHours()+"";
        String minute =date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()+"";
        time=hour + ":" + minute ;
        if(c_time<num){
            return "明天 "+time;
        }else{
            return time;
        }
    }
    /**
     * 判断当前时间是否在[startTime, endTime]区间，注意时间格式要一致
     *
     * @param nowTime 当前时间
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     * @author jqlin
     */
    public static boolean isEffectiveDate ( String start_Time, String end_Time) {

        SimpleDateFormat sdf= new SimpleDateFormat("HH:mm:ss");
            String ss=sdf.format(new Date());
        Date nowTime= null;
        Date startTime= null;
        Date endTime= null;
        try {
            nowTime = sdf.parse(ss);
            startTime = sdf.parse(start_Time);
            endTime = sdf.parse(end_Time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

}
